package com.triones.yjj.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.helper.LoginHelper;
import com.triones.yjj.entity.ActivityDO;
import com.triones.yjj.entity.GroupPurchaseGoodsItemDO;
import com.triones.yjj.entity.StaffActivityRelateDO;
import com.triones.yjj.entity.StaffDO;
import com.triones.yjj.entity.bo.ActivityListParams;
import com.triones.yjj.entity.vo.ActivityVO;
import com.triones.yjj.entity.vo.GroupPurchaseGoodsItemVO;
import com.triones.yjj.entity.vo.GroupPurchaseGoodsItemWxVO;
import com.triones.yjj.entity.vo.VisitAuthActivityListVO;
import com.triones.yjj.mapper.ActivityMapper;
import com.triones.yjj.mapper.GroupPurchaseGoodsItemMapper;
import com.triones.yjj.mapper.StaffActivityRelateMapper;
import com.triones.yjj.mapper.StaffMapper;
import com.triones.yjj.service.ActivityService;
import com.triones.yjj.service.GroupPurchaseGoodsItemService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 活动管理 service 业务实现
 *
 * @Author: triones
 */
@Service
@RequiredArgsConstructor
public class GroupPurchaseGoodsItemServiceImpl implements GroupPurchaseGoodsItemService {

    private final GroupPurchaseGoodsItemMapper groupPurchaseGoodsItemMapper;


    public List<GroupPurchaseGoodsItemWxVO> getListByGoodsId(Long goodsId) {
        QueryWrapper<GroupPurchaseGoodsItemDO> wrapper = Wrappers.query();
        wrapper.eq("group_purchase_goods_id",goodsId);
        List<GroupPurchaseGoodsItemWxVO> list =  groupPurchaseGoodsItemMapper.selectVoList(wrapper,GroupPurchaseGoodsItemWxVO.class);
        return list;
    }
    public GroupPurchaseGoodsItemVO getGroupPurchaseGoodsItemInfo(Long goodsId,Integer number) {
       //GroupPurchaseGoodsItemDO, GroupPurchaseGoodsItemVO
        QueryWrapper<GroupPurchaseGoodsItemDO> wrapper = Wrappers.query();
        wrapper.eq("group_purchase_goods_id",goodsId);
        if(number.equals(1)){
            wrapper.orderByAsc(" constitute_number");
        }else{
            wrapper.le("constitute_number",number);
            wrapper.orderByDesc(" constitute_number");
        }
        wrapper.last(" limit 1");
        List<GroupPurchaseGoodsItemVO> goodsItemVOS = groupPurchaseGoodsItemMapper.selectVoList(wrapper);
        if(goodsItemVOS!=null && goodsItemVOS.size()>0){
            GroupPurchaseGoodsItemVO vo = goodsItemVOS.get(0);
            List<GroupPurchaseGoodsItemWxVO> list =  groupPurchaseGoodsItemMapper.selectVoList(wrapper,GroupPurchaseGoodsItemWxVO.class);
            return vo;
        }else{
            return null;
        }

    }
}
